package com.guigu.controller.lq.controller;

import com.guigu.controller.lq.pojo.*;
import com.guigu.controller.lq.service.*;
import com.guigu.pojo.Vip;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController

public class LqPhysicaljgController {
    @Autowired
    LqPhysicaljgservice lqPhysicaljgservice;
    @Autowired
    LqPhysicalwtService lqPhysicalwtService;
    @Autowired
    LqVipSetvice lqVipSetvice;
    @Autowired
    LqPhysicallxService lqPhysicallxService;
    @Autowired
    LqTzdfService lqTzdfService;

    String vipid;
    Integer id;
    @RequestMapping("/tzjg")
    public PageVO<LqPhysicaljg> find(@RequestBody  PageVO pageVO){
        PageVO<LqPhysicaljg> all = lqPhysicaljgservice.find(pageVO.getPage(), pageVO.getNum(), pageVO.getVipname());
        return all;
    }

    @RequestMapping("/qx")
    public List<LqPhysicalwt> findwt(){
        List<LqPhysicalwt> findwt = lqPhysicalwtService.findwtqx();
        return findwt;
    }
    @RequestMapping("/byid")
    public Vip byid(@RequestBody Vip lqVip){
        Vip byid = lqVipSetvice.byid(lqVip.getVipid());
        return byid;
    }
    @RequestMapping("/tlx")
    public List<LqPhysicallx> cxtlx(){
        List<LqPhysicallx> cxtlx = lqPhysicallxService.cxtlx();
        return cxtlx;
    }

    @RequestMapping("/tadd")
    public int tzadd(@RequestBody LqPhysicaljg lqPhysicaljg){



        int tzadd = lqPhysicaljgservice.tzadd(lqPhysicaljg);
        vipid=lqPhysicaljg.getVipid();
        id=lqPhysicaljg.getId();

        return tzadd;
    }

    @RequestMapping("/tjtfs")
    public int wag(@RequestBody String [] aa) {
        System.out.println(id);
        LqTzdf lqTzdf = new LqTzdf();
        for(int i=0;i<aa.length;i++){
            if(i%4==0)
                lqTzdf.setQxfs(Integer.valueOf(aa[i]));
                lqTzdf.setYaxfs(Integer.valueOf(aa[i]));
                lqTzdf.setYixfs(Integer.valueOf(aa[i]));
                lqTzdf.setQyfs(Integer.valueOf(aa[i]));
                lqTzdf.setVipid(vipid);
                lqTzdf.setTid(id);

                lqTzdfService.tzfsadd(lqTzdf);
            }
        return   1;
        }


    @RequestMapping("/tzupid")
    public LqPhysicaljg selid(@RequestBody LqPhysicaljg lqPhysicaljg){
        LqPhysicaljg selid = lqPhysicaljgservice.selid(lqPhysicaljg.getId());
        return selid;
    }
    @RequestMapping("/tfs")
        public List<LqTzdf>tfs(@RequestBody LqTzdf lqTzdf){
        List<LqTzdf> selfs = lqTzdfService.selfs(lqTzdf.getTid());
        return selfs;
    }



    @RequestMapping("/tzup")
    public int tzup(@RequestBody LqPhysicaljg lqPhysicaljg){
        vipid=lqPhysicaljg.getVipid();
        id=lqPhysicaljg.getId();
        int tzup = lqPhysicaljgservice.tzup(lqPhysicaljg);
        return tzup;

    }
    @RequestMapping("/uptfs")
    public int upfs(@RequestBody String [] aa){
        List<LqTzdf> fsid = lqTzdfService.fsid(vipid);
        System.out.println(aa);
        LqTzdf lqTzdf = new LqTzdf();

        for(int i=0;i< aa.length;i++){

            if(i%4==0)
                lqTzdf.setQxfs(Integer.valueOf(aa[i]));
            lqTzdf.setYaxfs(Integer.valueOf(aa[i]));
            lqTzdf.setYixfs(Integer.valueOf(aa[i]));
            lqTzdf.setQyfs(Integer.valueOf(aa[i]));
            lqTzdf.setVipid(vipid);
            lqTzdf.setTid(id);
            lqTzdf.setId(fsid.get(0).getId());
           lqTzdfService.upfs(lqTzdf);
            System.out.println(aa[i]);
        }
        return   1;
    }
    @RequestMapping("/tzdel")
    public int tzdel(@RequestBody LqPhysicaljg lqPhysicaljg){
        int tzdel = lqPhysicaljgservice.tzdel(lqPhysicaljg.getId());
        return tzdel;
    }

}

